import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> list0 = new ArrayList<>();
        list0.add(1);
        list.add(list0);
        for(int i = 1;i < numRows;i++){
            list.add(new ArrayList<>());
            list.get(i).add(1);
            for(int j = 1;j < i;j++){
                list.get(i).add(list.get(i - 1).get(j-1)+ list.get(i - 1).get(j));
            }
            list.get(i).add(1);
        }
        return list;
    }


    public static void main(String[] args) {
        int a = 5;
        System.out.println(generate(a));
    }
    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        System.out.println("for下标遍历");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        System.out.println("foreach遍历");
        for (Integer x : list){
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("使用迭代器Iterator输出");
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
        System.out.println("使用迭代器ListIterator输出");
        ListIterator<Integer> it2 = list.listIterator();
        while(it2.hasNext()){
            System.out.print(it2.next() + " ");
        }
        System.out.println();
        System.out.println("使用迭代器ListIterator输出====扩展（反向输出）");
        ListIterator<Integer> it3 = list.listIterator(list.size());
        while(it3.hasPrevious()){
            System.out.print(it3.previous() + " ");
        }
        System.out.println();

    }
    public static void main1(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        System.out.println(list);



        List<Integer> list1 = list.subList(1,3);

        list1.set(1,999);
        System.out.println(list);
        System.out.println(list1);
    }

}